<?php

namespace app\api\model;

use app\common\model\TimeModel;

class MallTradeRecordLog extends TimeModel
{
    
    protected $name = "mall_trade_record_log";
    
    protected $deleteTime = "delete_time";
    
    
    public function mallOrder()
    {
        return $this->belongsTo('\app\admin\model\MallOrder', 'order_id', 'id');
    }
    
    public static function addRecord($userId, $orderId, $balancePayAmount, $surBalance = 0, $type = 2, $orderUserId = '')
    {
        //添加交易记录
        $tradeLogData = [
            'trade_type'    => $type,
            'amount'        => $balancePayAmount,
            'balance'       => $surBalance,
            'order_id'      => $orderId,
            'user_id'       => $userId,
            'order_user_id' => $orderUserId,
            'create_time'   => time(),
            'update_time'   => time(),
        ];
        $data         = MallTradeRecordLog::insertGetId($tradeLogData);
        if (false === $data) {
            _throwNewException('添加交易记录失败');
        } else {
            return $data;
        }
    }
    
}